package com.xm.hiber;

import com.xm.hiber.entity.Account;
import com.xm.hiber.entity.CreditAccount;
import com.xm.hiber.entity.DebitAccount;
import com.xm.hiber.util.HibernateUtil;
import org.hibernate.Session;
import org.hibernate.Transaction;


public class App {
    public static void main(String[] args) {
        Transaction transaction = null;
        try (Session session = HibernateUtil.getSessionFactory().openSession()) {
            // start a transaction
            transaction = session.beginTransaction();
            // save the account object
            Account account = new Account();
            account.setBalance(10000.0);
            account.setInterestRate(10.0);
            account.setOwner("Ramesh");
            session.save(account);

            CreditAccount creditAccount = new CreditAccount();
            creditAccount.setBalance(200.0);
            creditAccount.setInterestRate(1.0);
            creditAccount.setOwner("Jason");
            creditAccount.setCreditLimit(10);
            session.save(creditAccount);

            DebitAccount debitAccount = new DebitAccount();
            debitAccount.setBalance(300.0);
            debitAccount.setBalance(2.0);
            debitAccount.setOwner("Jet");
            debitAccount.setOverdraftFee(2.0);
            session.save(debitAccount);

            // commit transaction
            transaction.commit();
        }
        HibernateUtil.shutdown();
    }
}
